/* 参考 https://blog.csdn.net/Shinlyzsljay/article/details/78132793 */
Meteor.startup(() => {

  const WebSocket = require('ws');
  const wss = new WebSocket.Server({ port: 8080 });
  wss.on('connection', function connection(ws) {

   ws.on('message', function incoming(message) {
    console.log('received: %s', message);
   });

    setTimeout(function(){

      var max=100;
      var min=50;

      for(var i = 1; i < 50; i ++){
        setTimeout(function(){
          var x = random(0,min) % (max - min + 1) + min;
          var y = random(min,max) % (max - min + 1) + min;
          ws.send(x + "," + y)
        },1000 * i)
      }

    },9000)

  });

})

function random(upper,lower){
  return Math.floor(Math.random() * (upper - lower)) + lower;
}
